/**
 * gpms
 * 2012-8-1 下午3:01:56
 * 作者：陈志明
 * 
 */
package com.gpms.privilege.dao;

import java.util.List;

import oracle.jdbc.Const;

import com.gpms.common.dao.BaseDaoSupport;
import com.gpms.common.util.Constant;
import com.gpms.mapper.*;

/**
 * @author Jackie chen
 *
 */
public class UserDao extends BaseDaoSupport {
	
	/**
	 * 根据用户名查询用户
	 * @param user
	 * @return
	 */
	public Users findUserByName(Users user){
		return this.getSqlSession().selectOne(userMapper+".selectUserByName", user);
	}
	
	/**
	 * 根据用户名模糊查询用户
	 * @param user
	 * @return
	 */
	public List<Users> findUserByName_like(Users user){
		return this.getSqlSession().selectList(userMapper+".selectUserByName_like", user);
	}
	
	/**
	 * 查询所有用户
	 * @return
	 */
	public List<Users> findAllUser(){
		return this.getSqlSession().selectList(userMapper+".selectAllUser");
	}
	
	/**
	 * 根据用户ID查询用户
	 * @param user
	 * @return Users
	 */
	public Users findUserById(Users user){
		return this.getSqlSession().selectOne(userMapper+".selectByPrimaryKey",user.getId());
	}
	
	/**
	 * 保存用户
	 * @param user
	 * @return
	 */
	public int saveUser(Users user){
		return this.getSqlSession().insert(userMapper+".insertSelective",user);
	}
	
	/**
	 * 根据用户ID修改用户
	 * @param user
	 * @return
	 */
	public int alterUserById(Users user){
		return this.getSqlSession().update(userMapper+".updateByPrimaryKeySelective",user);
	}
	
	/**
	 * 根据用户ID删除用户
	 * @param user
	 * @return
	 */
	public int removeUserById(Users user){
		return this.getSqlSession().delete(userMapper+".deleteByPrimaryKey",user.getId());
	}
	
	/**
	 * 根据用户ID批量删除用户
	 * @param ids
	 * @return
	 */
	public int removeUserByIds(String ids){
		return this.getSqlSession().delete(userMapper+".deleteByIds",ids);
	} 
	
	/**
	 * 查询用户所属角色
	 * @param user
	 * @return
	 */
	public List<Role> findUserRoleByUserId(Users user){
		return this.getSqlSession().selectList(userRoleMapper+".selectRoleByUserId", user);
	}
	
	/**
	 * 查询用户所在分组
	 * @param user
	 * @return
	 */
	public List<Groups> findUserGroupByUserId(Users user){
		return this.getSqlSession().selectList(userMapper+".selectGroupByUserId",user);
	}
	
}
